Account = {
	//登入表單
	Login:{
		init:function(id){
			this.instance = Utility.createElement(
				"form", {id:id, method:"post"}, null, {onsubmit:function(){Account.Login.login();return false;}}, null);
			
			var element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			var elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"E-Mail："}, null, null, element);
			var elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			this.email = Account.Input.createInstance(
				"login-email", "text", "email", "form-input", "無效的 E-Mail 地址", 
				function(){
					if(this.value == ""){
						return false;
					}
					if(this.value.match(".+@.+") == null){
						return false;
					}
					return true;
				}
			);
			elementRight.appendChild(this.email);
			
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"密碼："}, null, null, element);
			elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			this.pw = Account.Input.createInstance(
				"login-pw", "password", "pw", "form-input", "請輸入 4~16 個有效字元（英文、數字或符號~!@*）", 
				function(){
					if(this.value == ""){
						return false;
					}
					if(this.value.match("[^a-zA-Z0-9~!@*]") != null || this.value.length < 4 || this.value.length > 16){
						return false;
					}
					return true;
				}
			);
			elementRight.appendChild(this.pw);
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			
			element = Utility.createElement("div", {className:"form-button"}, null, null, this.instance);
			elementLeft = Utility.createElement("div", {className:"form-button-left"}, null, null, element);
			var button = Utility.createElement(
				"input", 
				{type:"submit", value:"登入", className:"button"}, 
				null, Button.eventHandler, elementLeft
			);
			elementRight = Utility.createElement("div", {className:"form-button-right"}, null, null, element);
			var button = Utility.createElement(
				"input", 
				{type:"button", value:"取消", className:"button"}, 
				null, 
				Button.eventHandler, elementRight
			);
			button.onclick = function(){
				Message.hide("msg-login");
			};
		},
		check:function(){
			if(this.email.eventCheck && !this.email.eventCheck()){
				Message.show(
					"msg-login-check", 400, "E-Mail 格式錯誤", this.email.err, 
					new Message.Button("確定", function(){Message.hide();document.getElementById("login-email").focus();})
				);
				return false;
			}
			if(this.pw.eventCheck && !this.pw.eventCheck()){
				Message.show(
					"msg-login-check", 400, "密碼格式錯誤", this.pw.err, 
					new Message.Button("確定", function(){Message.hide();document.getElementById("login-pw").focus();})
				);
				return false;
			}
			return true;
		},
		eventEnter:function(e){
			e = e || window.event;
			var code = e.keyCode || e.charCode || e.which;
			if(code == 13){
				Account.Login.login();
			}
		},
		login:function(){
			if(Account.Login.check()){
				Message.show("msg-login-processing", 400, "系統處理中", Ajax.loadingImg);
				Ajax.sendRequest(
					"post", "/exe/Login", 
					"email=" + Account.Login.email.value + "&password=" + Account.Login.pw.value,
					true,
					function(req){
						var result = req.getResponseHeader("result");
						Message.hide("msg-login-processing");
						switch(result){
							case "0":
								Message.show(
									"msg-login-result", 400, "登入失敗", "錯誤的 E-Mail 或密碼。",
									new Message.Button(
										"確定", function(){Message.hide();document.getElementById("login-email").focus();})
								);
								return;
							case "1":
								Message.hide("msg-login");
								Message.show("msg-login-result", 400, "登入成功", "歡迎！", Button.buttonReload);
								Button.showLoginTools();
								return;
							default:
								Message.show(
									"msg-login-result", 400, "登入失敗", "系統錯誤，請稍後重試或聯絡客服。",
									new Message.Button(
										"確定", function(){Message.hide();document.getElementById("login-email").focus();})
								);
								return;
						}
					}
				);
			}
		}
	},
	//註冊表單
	Register:{
		init:function(id){
			this.instance = Utility.createElement(
				"form", {id:id, method:"post"}, null, {onsubmit:function(){Account.Register.register();return false;}}, null);
			
			var element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			var elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"名稱："}, null, null, element);
			var elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			this.name = Account.Input.createInstance(
				"register-name", "text", "name", "form-input", "請輸入名稱", 
				function(){
					if(this.value == ""){
						return false;
					}
					return true;
				}
			);
			elementRight.appendChild(this.name);
			Utility.createElement("div", {className:"form-element-tip", innerHTML:"請輸入您公開用的名稱"}, null, null, elementRight);
			
			
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"E-Mail："}, null, null, element);
			elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			this.email = Account.Input.createInstance(
				"register-email", "text", "email", "form-input", "無效的 E-Mail 地址",
				function(){
					if(this.value.match(".+@.+") == null){
						return false;
					}
					return true;
				}
			);
			elementRight.appendChild(this.email);
			Utility.createElement(
				"div", 
				{className:"form-element-tip", innerHTML:"請輸入有效的 E-Mail 以收取驗證信"}, 
				null, null, elementRight);
			
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"密碼："}, null, null, element);
			elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			this.pw = Account.Input.createInstance(
				"register-pw", "password", "pw", "form-input", "請輸入 4~16 個有效字元（英文、數字或符號~!@*）",
				function(){
					if(this.value.match("[^a-zA-Z0-9~!@*]") != null || this.value.length < 4 || this.value.length > 16){
						return false;
					}
					return true;
				}
			);
			elementRight.appendChild(this.pw);
			Utility.createElement(
				"div", 
				{className:"form-element-tip", 
				 innerHTML:"請輸入 4~16 個有效字元（英文、數字或符號~!@*）"}, 
				 null, null, elementRight
			);
			
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"確認密碼："}, null, null, element);
			elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			this.pwConfirm = Account.Input.createInstance(
				"register-confirm", "password", "pwConfirm", "form-input", "密碼輸入不一致",
				function(){
					if(this.value != Account.Register.pw.value){
						return false;
					}
					return true;
				}
			);
			elementRight.appendChild(this.pwConfirm);
			Utility.createElement("div", {className:"form-element-tip", innerHTML:"請再次輸入密碼"}, null, null, elementRight);
			
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"驗證碼："}, null, null, element);
			elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			this.secureCode = Account.Input.createInstance(
				"register-secure-code", "text", "secureCode", "form-input", "驗證碼錯誤", 
				function(){
					if(this.value.length != 4 || this.value.match("[^0-9]") != null){
						return false;
					}
					return true;
				}
			);
			this.secureCode.style.width = "230px";
			elementRight.appendChild(this.secureCode);
			var code = Utility.createElement(
				"img", 
				{src:"/exe/SecureCode?random=" + (new Date()).getMilliseconds()}, 
				{verticalAlign:"middle"}, null, elementRight
			);
			code.style.marginLeft = "5px";
			Utility.createElement("div", {className:"form-element-tip", innerHTML:"請輸入右方驗證碼"}, null, null, elementRight);
			
			element = Utility.createElement(
				"div", 
				{className:"form-element mark-red", 
				 innerHTML:"點擊註冊代表您已閱讀並同意本站的<a href='/service-terms.jsp' target='_blank'>使用條款</a>。"}, 
				{textAlign:"center", fontSize:"16px", paddingTop:"20px"}, null, this.instance
			);
			
			element = Utility.createElement("div", {className:"form-button"}, null, null, this.instance);
			elementLeft = Utility.createElement("div", {className:"form-button-left"}, null, null, element);
			var button = Utility.createElement(
				"input", 
				{id:"msg-register-submit", type:"submit", value:"註冊", className:"button"}, 
				null, Button.eventHandler, elementLeft
			);
			elementRight = Utility.createElement("div", {className:"form-button-right"}, null, null, element);
			button = Utility.createElement(
				"input", 
				{type:"button", value:"取消", className:"button"}, 
				null, 
				Button.eventHandler, elementRight
			);
			button.onclick = function(){
				Message.hide("msg-register");
			};
		},
		check:function(){
			console.log(this);
			if(this.name.eventCheck && !this.name.eventCheck()){
				Message.show(
					"msg-register-check", 400, "名稱格式錯誤", this.name.err,
					new Message.Button("確定", function(){Message.hide();document.getElementById("register-name").focus();})
				);
				return false;
			}
			if(this.email.eventCheck && !this.email.eventCheck()){
				Message.show(
					"msg-register-check", 400, "E-Mail 格式錯誤", this.email.err,
					new Message.Button("確定", function(){Message.hide();document.getElementById("register-email").focus();})
				);
				return false;
			}
			if(this.pw.eventCheck && !this.pw.eventCheck()){
				Message.show(
					"msg-register-check", 400, "密碼格式錯誤", this.pw.err,
					new Message.Button("確定", function(){Message.hide();document.getElementById("register-pw").focus();})
				);
				return false;
			}
			if(this.pwConfirm.eventCheck && !this.pwConfirm.eventCheck()){
				Message.show(
					"msg-register-check", 400, "確認密碼格式錯誤", this.pwConfirm.err,
					new Message.Button("確定", function(){Message.hide();document.getElementById("register-confirm").focus();})
				);
				return false;
			}
			if(this.secureCode.eventCheck && !this.secureCode.eventCheck()){
				Message.show(
					"msg-register-check", 400, "驗證碼格式錯誤", this.secureCode.err,
					new Message.Button("確定", function(){Message.hide();document.getElementById("register-secure-code").focus();})
				);
				return false;
			}
			return true;
		},
		register:function(form){
			if(Account.Register.check()){
				Message.show("msg-register-processing", 400, "系統處理中", Ajax.loadingImg);
				Ajax.sendRequest(
					"post", "/exe/Join", 
					"name=" + encodeURIComponent(Account.Register.name.value) + "&email=" + Account.Register.email.value
							+ "&password=" + Account.Register.pw.value	+ "&code=" + Account.Register.secureCode.value,
					true,
					function(req){				
						var result = req.getResponseHeader("result");
						Message.hide("msg-register-processing");
						switch(result){
							case "0":
								Message.show("msg-register-result", 400, "註冊失敗", "此 E-Mail 已被註冊。",
									new Message.Button(
										"確定", function(){Message.hide();document.getElementById("register-email").focus();})
								);
								return;
							case "1":
								Message.hide("msg-register");
								Message.show(
									"msg-register-result", 400, "註冊成功", 
									"歡迎！<br/>請至您註冊的電子信箱收取驗證信以完成驗證。", 
									Button.buttonReload
								);
								return;
							case "2":
								Message.show("msg-register-result", 400, "註冊失敗", "驗證碼輸入錯誤。",
									new Message.Button(
										"確定", function(){Message.hide();document.getElementById("register-secure-code").focus();})
								);
								return;
							default:
								Message.show("msg-register-result", 400, "註冊失敗", "系統錯誤，請稍後重試或聯絡客服。",
									new Message.Button(
										"確定", function(){Message.hide();document.getElementById("register-name").focus();})
								);
								return;
						}
					}
				);
			}
		}
	},
	//建立譯者資料
	ProfileCreate:{
		addSpec:function(){
			var form = document.getElementById("profile-create");
			var from = form.fromLang.options[form.fromLang.selectedIndex];
			var to = form.toLang.options[form.toLang.selectedIndex];
			if(from.value == to.value){
				Message.show("add-spec-error", 400, "新增專長錯誤", "翻譯專長來源與目的須為不同語言", Message.BUTTON_OK);
				return;
			}
			for(var i = 0; i < Account.ProfileCreate.specFromLang.length; i++){
				if(Account.ProfileCreate.specFromLang[i] == parseInt(from.value) 
					&& Account.ProfileCreate.specToLang[i] == parseInt(to.value)){
					Message.show("add-spec-error", 400, "新增專長錯誤", "此翻譯專長已新增", Message.BUTTON_OK);
					return;
				}
			}
			Account.ProfileCreate.specFromLang.push(parseInt(from.value));
			Account.ProfileCreate.specToLang.push(parseInt(to.value));
			Account.ProfileCreate.createSpec(from.value, from.innerHTML, to.value, to.innerHTML);
		},
		createSpec:function(fromId, fromTitle, toId, toTitle){
			var specDiv = document.getElementById("profile-create-spec");
			var selector = document.getElementById("profile-create-spec-selector");
			var spec = Utility.createElement(
				"div",
				{id:"spec-" + fromId + "-" + toId, className:"profile-element"},
				null, null, specDiv, selector
			);
			var specLeft = Utility.createElement("div", {className:"profile-element-left profile-spec-left"}, null, null, spec);
			Utility.createElement(
				"span",
				{innerHTML:"從<span class='spec-lang mark-red'>" + fromTitle + "</span>"
					 + "翻譯至<span class='spec-lang mark-red'>" + toTitle + "</span>"},
				null, null, specLeft
			);
			var specRight = Utility.createElement("div", {className:"profile-element-right profile-spec-right"}, null, null, spec);
			Utility.createElement(
				"input",
				{id:fromId + "-" + toId, from:parseInt(fromId), to:parseInt(toId), value:"移除", className:"input-button", type:"button"},
				null,
				{onclick:function(){Account.ProfileCreate.removeSpec(this.from, this.to)}},
				specRight
			);
		},
		removeSpec:function(from, to){
			var specDiv = document.getElementById("profile-create-spec");
			var spec = document.getElementById("spec-" + from + "-" + to);
			specDiv.removeChild(spec);
			for(var i = 0; i < Account.ProfileCreate.specFromLang.length; i++){
				if(Account.ProfileCreate.specFromLang[i] == from && Account.ProfileCreate.specToLang[i] == to){
					Account.ProfileCreate.specFromLang.splice(i, 1);
					Account.ProfileCreate.specToLang.splice(i, 1);
					break;
				}
			}
		},
		check:function(form){
			if(form.description.value == ""){
				Message.show("msg-profile-create-check", 400, "格式錯誤", "請填寫自我介紹", Message.BUTTON_OK);
				return false;
			}
			if(form.description.value.length > 255){
				Message.show("msg-profile-create-check", 400, "格式錯誤", "自我介紹不得超過 255 個字", Message.BUTTON_OK);
				return false;
			}
			if(form.education.value.length > 255){
				Message.show("msg-profile-create-check", 400, "格式錯誤", "學歷不得超過 255 個字", Message.BUTTON_OK);
				return false;
			}
			if(form.certification.value.length > 255){
				Message.show("msg-profile-create-check", 400, "格式錯誤", "語言相關證照不得超過 255 個字", Message.BUTTON_OK);
				return false;
			}
			if(form.experience.value.length > 255){
				Message.show("msg-profile-create-check", 400, "格式錯誤", "工作經歷不得超過 255 個字", Message.BUTTON_OK);
				return false;
			}
			if(Account.ProfileCreate.specFromLang.length == 0){
				Message.show("msg-profile-create-check", 400, "格式錯誤", "請至少新增一個翻譯專長", Message.BUTTON_OK);
				return false;
			}
			return true;
		},
		show:function(status){
			if(status == -1){
				Message.show("profile-create-error", 400, "權限不足", "您必須先驗證 E-Mail 才能建立譯者資料", Message.BUTTON_OK);
				return;
			}
			document.getElementById("profile-content").style.display = "none";
			document.getElementById("profile-create").style.display = "block";
		},
		hide:function(){
			document.getElementById("profile-content").style.display = "block";
			document.getElementById("profile-create").style.display = "none";
		},
		setValue:function(description, education, certification, experience, specFromLang, specToLang){
			var form = document.getElementById("profile-create");
			form.description.value = description.replace(/<br\/>/g, "\r\n");
			form.education.value = education.replace(/<br\/>/g, "\r\n");
			form.certification.value = certification.replace(/<br\/>/g, "\r\n");
			form.experience.value = experience.replace(/<br\/>/g, "\r\n");
			form.submit.value = "修改";
			form.onsubmit = function(){
				Account.ProfileCreate.create(this, true);
				return false;
			};
			while(this.specFromLang.length != 0){
				this.removeSpec(this.specFromLang[0], this.specToLang[0]);
			}
			
			this.specFromLang = new Array(0);
			this.specToLang = new Array(0);
			var specFrom = specFromLang.split(";");
			var specTo = specToLang.split(";");
			var specDiv = document.getElementById("profile-create-spec");
			var selector = document.getElementById("profile-create-spec-selector");
			for(var i = 0; i < specFrom.length; i++){
				var from = specFrom[i].split(",");
				var to = specTo[i].split(",");
				this.specFromLang.push(parseInt(from[0]));
				this.specToLang.push(parseInt(to[0]));
				this.createSpec(from[0], from[1], to[0], to[1]);
			}
		},
		specFromLang:new Array(0),
		specToLang:new Array(0),
		create:function(form, modify){
			if(Account.ProfileCreate.check(form)){
				Message.show("msg-profile-create-processing", 400, "系統處理中", Ajax.loadingImg);
				var fromLang = "";
				var toLang = "";
				for(var i = 0; i < Account.ProfileCreate.specFromLang.length; i++){
					if(i != Account.ProfileCreate.specFromLang.length - 1){
						fromLang += Account.ProfileCreate.specFromLang[i] + ",";
						toLang += Account.ProfileCreate.specToLang[i] + ",";
					}else{
						fromLang += Account.ProfileCreate.specFromLang[i];
						toLang += Account.ProfileCreate.specToLang[i];
					}
				}
				if(modify){
					Ajax.sendRequest(
						"post", "/exe/member/ModifyProfile",
						"description=" + encodeURIComponent(form.description.value)
							+ "&education=" + encodeURIComponent(form.education.value)
							+ "&certification=" + encodeURIComponent(form.certification.value)
							+ "&experience=" + encodeURIComponent(form.experience.value)
							+ "&from_lan=" + fromLang + "&to_lan=" + toLang,
						true, 
						function(req){
							var result = req.getResponseHeader("result");
							Message.hide("msg-profile-create-processing");
							if(result == "true"){
								Message.show(
									"msg-profile-create-result", 400, "修改成功", "譯者資料已成功修改", Button.buttonReload);
							}else{
								Message.show(
									"msg-profile-create-result", 400, "修改失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
							}
						}
					);
				}else{
					Ajax.sendRequest(
						"post", "/exe/member/CreateProfile",
						"description=" + encodeURIComponent(form.description.value)
							+ "&education=" + encodeURIComponent(form.education.value)
							+ "&certification=" + encodeURIComponent(form.certification.value)
							+ "&experience=" + encodeURIComponent(form.experience.value)
							+ "&from_lan=" + fromLang + "&to_lan=" + toLang,
						true, 
						function(req){
							var result = req.getResponseHeader("result");
							if(result == "true"){
								Message.show(
									"msg-profile-create-result", 400, "建立成功", "譯者資料已成功修改", Button.buttonReload);
							}else{
								Message.show("msg-profile-create-result", 400, "建立失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
							}
						}
					);
				}
			}
		}
	},
	//新增訊息
	MessageCreate:{
		init:function(id){
			this.instance = Utility.createElement(
				"form", {id:id, method:"post"}, null, {onsubmit:function(){Account.MessageCreate.create();return false;}}, null);
			
			var element = Utility.createElement("div", {className:"form-element", innerHTML:"收件人："}, null, null, this.instance);
			var input = Utility.createElement(
				"input", {name:"uname", className:"form-input", disabled:"disabled"}, null, null, element);
				
			element = 
				Utility.createElement("input", {type:"hidden", name:"uid"}, null, null, this.instance);
				
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			var textarea = Utility.createElement("textarea", {name:"content"}, {width:"90%", marginTop:"10px"}, null, element);
			
			element = Utility.createElement("div", {className:"form-button"}, null, null, this.instance);
			var elementLeft = Utility.createElement("div", {className:"form-button-left"}, null, null, element);
			var button = Utility.createElement(
				"input", 
				{type:"submit", value:"傳送", className:"button"}, 
				null, Button.eventHandler, elementLeft
			);
			var elementRight = Utility.createElement("div", {className:"form-button-right"}, null, null, element);
			button = Utility.createElement(
				"input", 
				{type:"button", value:"取消", className:"button"}, 
				null, 
				Button.eventHandler, elementRight
			);
			button.onclick = function(){
				Message.hide("msg-message-send");
			};
		},
		check:function(){
			if(this.instance.content.value == ""){
				Message.show("msg-message-send-check", 400, "內容格式錯誤", "請輸入訊息內容", Message.BUTTON_OK);
				return false;
			}
			if(this.instance.content.value.length > 255){
				Message.show("msg-message-send-check", 400, "內容格式錯誤", "訊息字數不得超過 255 字", Message.BUTTON_OK);
				return false;
			}
			if(this.instance.uid.value == ""){
				Message.show("msg-message-send-check", 400, "收件人錯誤", "系統錯誤，請稍後重試或聯絡客服。", Message.BUTTON_OK);
				return false;
			}
			return true;
		},
		create:function(){
			if(Account.MessageCreate.check()){
				Message.show("msg-message-send-processing", 400, "系統處理中", Ajax.loadingImg);
				Ajax.sendRequest(
					"post", "/exe/member/CreateMessage", 
					"receiver_id=" + this.instance.uid.value + "&content=" + encodeURIComponent(this.instance.content.value),
					true,
					function(req){
						Message.hide("msg-message-send-processing");
						var result = req.getResponseHeader("result");
						if(result == "true"){
							Message.show(
								"msg-message-send-result", 400, "處理成功", "您的訊息已成功傳送", Button.buttonReload);
						}else{
							Message.show(
								"msg-message-send-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
						}
					}
				);
			}
		},
		setValue:function(uid, uname){
			Account.MessageCreate.instance.uid.value = uid;
			Account.MessageCreate.instance.uname.value = uname;
		}
	},
	//刪除訊息
	deleteMessage:function(id){
		if(!id){
			return;
		}
		
		var del = function(){
			Message.show("msg-delete-message-processing", 400, "系統處理中", Ajax.loadingImg);
			Ajax.sendRequest(
				"post", "/exe/member/DeleteMessage", "id=" + id, true, 
				function(req){
					Message.hide("msg-delete-message-processing");
					var result = req.getResponseHeader("result");
					if(result == "true"){
						Message.show(
							"msg-delete-message-result", 400, "處理成功", "已成功刪除訊息", Button.buttonReload);
					}else{
						Message.show("msg-delete-message-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
					}
				}
			);
		}
		
		Message.show(
			"msg-delete-message-confirm", 400, "確認刪除訊息", "是否確定刪除此訊息？", 
			new Message.Button("確定", del), Message.BUTTON_CANCEL
		);
	},
	//更改密碼
	PasswordChange:{
		init:function(){
			this.instance = Utility.createElement(
				"form", {method:"post"}, null, {onsubmit:function(){Account.PasswordChange.change();return false;}}, null);
			
			var element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			var elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"舊密碼："}, null, null, element);
			var elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			Utility.createElement("input", {name:"oldPW", type:"password", className:"form-input"}, null, null, elementRight);
			Utility.createElement("div", {className:"form-element-tip", innerHTML:"請輸入舊密碼"}, null, null, elementRight);
			
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			elementLeft = Utility.createElement("div", {className:"form-element-left", innerHTML:"新密碼："}, null, null, element);
			elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			Utility.createElement("input", {name:"newPW", type:"password", className:"form-input"}, null, null, elementRight);
			Utility.createElement(
				"div", 
				{className:"form-element-tip", innerHTML:"請輸入 4~16 個有效字元（英文、數字或符號~!@*）"}, 
				null, null, elementRight
			);
						
			element = Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			elementLeft = 
				Utility.createElement("div", {className:"form-element-left", innerHTML:"確認新密碼："}, null, null, element);
			elementRight = Utility.createElement("div", {className:"form-element-right"}, null, null, element);
			Utility.createElement("input", {name:"confirmPW", type:"password", className:"form-input"}, null, null, elementRight);
			Utility.createElement("div", {className:"form-element-tip", innerHTML:"請再次輸入新密碼"}, null, null, elementRight);
				
			Utility.createElement("div", {className:"form-element"}, null, null, this.instance);
			
			element = Utility.createElement("div", {className:"form-button"}, null, null, this.instance);
			elementLeft = Utility.createElement("div", {className:"form-button-left"}, null, null, element);
			Utility.createElement(
				"input", {type:"submit", value:"確定", className:"button"}, null, Button.eventHandler, elementLeft);
			elementRight = Utility.createElement("div", {className:"form-button-right"}, null, null, element);
			var button = Utility.createElement(
				"input", {type:"button", value:"取消", className:"button"}, null, Button.eventHandler, elementRight);
			button.onclick = function(){Message.hide("msg-pw-change");};
		},
		show:function(){
			this.init();
			Message.show('msg-pw-change', 500, '更改密碼', this.instance);
			this.instance.oldPW.focus();
		},
		check:function(){
			if(this.instance.oldPW.value.match("[^a-zA-Z0-9~!@*]") != null || 
				this.instance.oldPW.value.length < 4 || this.instance.oldPW.value.length > 16){
				Message.show(
					"msg-pw-change-check", 400, "舊密碼格式錯誤", "請輸入 4~16 個有效字元（英文、數字或符號~!@*）", 
					new Message.Button("確定", function(){Message.hide();Account.PasswordChange.instance.oldPW.focus();})
				);
				return false;
			}
			
			if(this.instance.newPW.value.match("[^a-zA-Z0-9~!@*]") != null || 
				this.instance.newPW.value.length < 4 || this.instance.newPW.value.length > 16){
				Message.show(
					"msg-pw-change-check", 400, "新密碼格式錯誤", "請輸入 4~16 個有效字元（英文、數字或符號~!@*）", 
					new Message.Button("確定", function(){Message.hide();Account.PasswordChange.instance.newPW.focus();})
				);
				return false;
			}
			
			if(this.instance.confirmPW.value != this.instance.newPW.value){
				Message.show(
					"msg-pw-change-check", 400, "新密碼確認格式錯誤", "新密碼確認輸入不一致", 
					new Message.Button("確定", function(){Message.hide();Account.PasswordChange.instance.confirmPW.focus();})
				);
				return false;
			}
			return true;
		},
		change:function(){
			if(this.check()){
				Message.hide("msg-pw-change");
				Message.show("msg-pw-change-processing", 400, "系統處理中", Ajax.loadingImg);
				Ajax.sendRequest(
					"post", "/exe/member/ChangePassword", 
					"old_password=" + this.instance.oldPW.value + "&new_password=" + this.instance.newPW.value,
					true,
					function(req){
						Message.hide("msg-pw-change-processing");
						var result = req.getResponseHeader("result");
						if(result == "true"){
							Message.show(
								"msg-pw-change-result", 400, "處理成功", "您的密碼已成功更改", Message.BUTTON_OK);
						}else{
							Message.show(
								"msg-pw-change-result", 400, "處理失敗", "您的資料輸入錯誤", Message.BUTTON_OK);
						}
					}
				);
			}
		}
	},
	//重新寄發驗證信
	verifyEmail:function(){
		Message.show("msg-verify-email-processing", 400, "系統處理中", Ajax.loadingImg);
		Ajax.sendRequest(
			"post", "/exe/member/SendVerifyEmail", "", true, 
			function(req){
				Message.hide("msg-verify-email-processing");
				Message.show("msg-verify-email-result", 400, "寄送成功", "驗證信已成功寄送至您所註冊的電子信箱", Message.BUTTON_OK);
			}
		);
	},
	//驗證手機
	verifyPhone:function(form, step2){
		if(form.step.value == "1"){
			if(form.phone.value == ""){
				Message.show("msg-create-phone-error", 400, "手機號碼格式錯誤", "請輸入手機號碼", Message.BUTTON_OK);
				return;
			}
			if(form.phone.value.match("0{1}9{1}[0-9]{8}") == null){
				Message.show(
					"msg-create-phone-error", 400, "手機號碼格式錯誤", "請輸入 \"09\" 開頭的 10 位數字", Message.BUTTON_OK);
				return;
			}
		}else if(form.step.value == "2"){
			if(form.code.value == ""){
				Message.show("msg-verify-error", 400, "驗證碼格式錯誤", "請輸入驗證碼", Message.BUTTON_OK);
				return;
			}
		}else{
			return;
		}
		
		if(form.step.value == "1"){
			Message.show("msg-create-phone-processing", 400, "系統處理中", Ajax.loadingImg);
			Ajax.sendRequest(
				"post", "/exe/member/CreatePhone", "phone=" + form.phone.value, true, 
				function(req){
					Message.hide("msg-create-phone-processing");
					var result = req.getResponseHeader("result");
					if(result == "true"){
						Message.show(
							"msg-create-phone-result", 400, "處理成功", "驗證簡訊已成功寄出，請立即檢查手機以收取驗證碼。", 
							Message.BUTTON_OK
						);
						form.phone.disabled = "disabled";
						form.step.value = "2";
						document.getElementById(step2).style.display = "block";
					}else{
						Message.show(
							"msg-create-phone-result", 400, "處理失敗", 
							"您填寫的手機號碼可能有錯誤，或者與其他帳戶的號碼重複。", 
							Button.buttonReload
						);
					}
				}
			);
		}else if(form.step.value == "2"){
			Message.show("msg-verify-processing", 400, "系統處理中", Ajax.loadingImg);
			Ajax.sendRequest(
				"post", "/exe/Verify", "source=phone&id=&code=" + form.code.value, true, 
				function(req){
					Message.hide("msg-verify-processing");
					var result = req.getResponseHeader("result");
					if(result == "true"){
						Message.show(
							"msg-verify-result", 400, "處理成功", "恭喜！您已成功通過手機驗證。", Button.buttonReload);
					}else{
						Message.show("msg-verify-result", 400, "處理失敗", "驗證碼輸入錯誤", Message.BUTTON_OK);
					}
				}
			);
		}
	},
	//加入關注列表
	addFavorite:function(uid, error){
		if(!uid){
			Message.show("msg-add-favorite-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
			return;
		}
		if(error == -1){
			Message.show("msg-add-favorite-result", 400, "權限不足", "請先登入以使用此功能", Message.BUTTON_OK);
			return;
		}
		
		
		Message.show("msg-add-favorit-processing", 400, "系統處理中", Ajax.loadingImg);
		Ajax.sendRequest(
			"post", "/exe/member/AddFavorite", "id=" + uid, true, 
			function(req){
				Message.hide("msg-add-favorit-processing");
				var result = req.getResponseHeader("result");
				if(result == "true"){
					Message.show(
						"msg-add-favorit-result", 400, "處理成功", "已成功加入至關注列表", Button.buttonReload);
				}else{
					Message.show("msg-add-favorit-result", 400, "處理失敗", "關注列表人數已達上限", Message.BUTTON_OK);
				}
			}
		);
	},
	//刪除關注列表
	deleteFavorite:function(uid){
		if(!uid){
			Message.show("msg-delete-favorite-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
			return;
		}
		
		var send = function(){
			Message.show("msg-delete-favorit-processing", 400, "系統處理中", Ajax.loadingImg);
			Ajax.sendRequest(
				"post", "/exe/member/DeleteFavorite", "id=" + uid, true, 
				function(req){
					Message.hide("msg-delete-favorit-processing");
					var result = req.getResponseHeader("result");
					if(result == "true"){
						Message.show(
							"msg-delete-favorit-result", 400, "處理成功", "已成功從關注列表中刪除", Button.buttonReload);
					}else{
						Message.show("msg-delete-favorit-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
					}
				}
			);
		}
		
		Message.show(
			"msg-delete-favorite-confirm", 400, "確認刪除此使用者", 
			"是否確定刪除此使用者？<br/>您之後仍可以再次將此使用者加入至關注列表。", 
			new Message.Button("確定", send), Message.BUTTON_CANCEL
		);
	},
	//提款
	withdraw:function(form){
		if(form.money.value == ""){
			Message.show("msg-withdraw-check", 400, "提款金額格式錯誤", "請輸入提款金額", Message.BUTTON_OK);
			return;
		}
		if(form.money.value.match("[^0-9]") != null){
			Message.show("msg-withdraw-check", 400, "提款金額格式錯誤", "請輸入阿拉伯數字", Message.BUTTON_OK);
			return;
		}
		var money = parseInt(form.money.value);
		var reserved = parseInt(form.reserved.value);
		if(money < 200 || money > 200000){
			Message.show(
				"msg-withdraw-check", 400, "提款金額錯誤", "提款金額必須介於 NTD 200 元至 100000 元之間。", 
				Message.BUTTON_OK
			);
			return;
		}
		if(money > reserved){
			Message.show(
				"msg-withdraw-check", 400, "提款金額錯誤", "提款金額不得超過目前可領取的金額：NTD " + reserved + " 元", Message.BUTTON_OK);
			return;
		}
		if(form.email.value == ""){
			Message.show("msg-withdraw-check", 400, "PayPal 帳號格式錯誤", "請輸入 PayPal E-Mail 帳號", Message.BUTTON_OK);
			return;
		}
		if(form.email.value.match(".+@.+") == null){
			Message.show("msg-withdraw-check", 400, "PayPal 帳號格式錯誤", "無效的 PayPal E-Mail 帳號", Message.BUTTON_OK);
			return;
		}
		if(!form.agree.checked){
			Message.show("msg-withdraw-check", 400, "錯誤", "請先勾選同意注意事項", Message.BUTTON_OK);
			return;
		}
		
		var send = function(){
			Message.show("msg-withdraw-processing", 400, "系統處理中", Ajax.loadingImg);
			Ajax.sendRequest(
				"post", "/exe/member/paypal/WithdrawMoney", 
				"money=" + form.money.value + "&paypal_email=" + form.email.value,	true,
				function(req){
					Message.hide("msg-withdraw-processing");
					var result = req.getResponseHeader("result");
					if(result == "true"){
						Message.show(
							"msg-withdraw-result", 500, "處理成功", 
							"您的提款要求已成功送出，我們將在三個工作天之內盡快處理。<br/>"
							+ "請查閱<a href='/account/transaction.jsp'>交易紀錄</a>以持續追蹤處理進度。", 
							Button.buttonReload
						);
					}else{
						Message.show("msg-withdraw-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
					}
				}
			);
		}
		
		Message.show(
			"msg-withdraw-confirm", 400, "確認提款", "是否確定提款？請務必確認提供的資料正確！", new Message.Button("確定", send), Message.BUTTON_CANCEL);
	},
	//更改E-Mail通知設定
	changeNotify:function(open){
		if(open){
			Message.show("msg-change-notify-processing", 400, "系統處理中", Ajax.loadingImg);
			Ajax.sendRequest(
				"post", "/exe/member/ChangeNotify", "notify=true", true, 
				function(req){
					Message.hide("msg-change-notify-processing");
					var result = req.getResponseHeader("result");
					if(result == "true"){
						Message.show("msg-change-notify-result", 400, "處理成功", "已開啟 E-Mail 通知", Button.buttonReload);
					}else{
						Message.show("msg-change-notify-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
					}
				}
			);
		}else{
			var send = function(){
				Message.show("msg-change-notify-processing", 400, "系統處理中", Ajax.loadingImg);
				Ajax.sendRequest(
					"post", "/exe/member/ChangeNotify", "notify=false", true, 
					function(req){
						Message.hide("msg-change-notify-processing");
						var result = req.getResponseHeader("result");
						if(result == "true"){
							Message.show("msg-change-notify-result", 400, "處理成功", "已關閉 E-Mail 通知", Button.buttonReload);
						}else{
							Message.show("msg-change-notify-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
						}
					}
				);
			}
			
			Message.show(
				"msg-change-notify-confirm", 400, "確認關閉 E-Mail 通知", 
				"是否確定關閉 E-Mail 通知？<br/>關閉後，您將無法透過 E-Mail 收到重要的系統訊息。", 
				new Message.Button("確定", send), Message.BUTTON_CANCEL
			);
		}
	},
	//更新Session
	updateUser:function(){
		Message.show("msg-update-user-processing", 400, "系統處理中", Ajax.loadingImg);
		Ajax.sendRequest(
			"post", "/exe/member/UpdateUser", "", true, 
			function(req){
				Message.hide("msg-update-user-processing");
				var result = req.getResponseHeader("result");
				if(result == "true"){
					Message.show("msg-update-user-result", 400, "處理成功", "已取得最新資料", Button.buttonReload);
				}else{
					Message.show("msg-update-user-result", 400, "處理失敗", "請稍後重試或聯絡客服", Message.BUTTON_OK);
				}
			}
		);
	},
	
	Input:{
		createInstance:function(id, type, name, className, err, eventCheck){
			var input = Utility.createElement(
				"input",
				{id:id, type:type, name:name, className:className, err:err},
				null, null, null
			);
			input.eventCheck = eventCheck;
			return input;
		}
	}
};